package com.sharp.schedule.controller;

import com.sharp.kernel.config.response.Response;
import com.sharp.kernel.config.response.ResponseHandler;
import com.sharp.kernel.vo.common.CommonResVO;
import com.sharp.kernel.vo.query.QueryRespVO;
import com.sharp.schedule.service.ScheduleService;
import com.sharp.schedule.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Title: ScheduleController
 * Description: Copyright: Copyright (c) 2019 Company: BHFAE
 *
 * @author Sharp
 * @date 2020/10/16 18:10
 */
@Api(value = "定时任务管理", tags = "定时任务管理")
@RestController("ScheduleController")
@RequestMapping(value = "/schedule")
public class ScheduleController {
    @Resource
    private ScheduleService scheduleService;

    @RequestMapping(value = "/query", method = RequestMethod.POST)
    @ApiOperation(value = "获取注册定时任务", notes = "获取注册定时任务")
    public ResponseEntity<Response<QueryRespVO<QueryScheduleRes>>> getSchedule(@RequestBody QueryScheduleReq req) {
        QueryRespVO<QueryScheduleRes> res = scheduleService.querySchedule(req);
        return ResponseHandler.generateResponse(res);
    }

    @RequestMapping(value = "/history/query", method = RequestMethod.POST)
    @ApiOperation(value = "获取定时任务执行情况", notes = "获取定时任务执行情况")
    public ResponseEntity<Response<QueryRespVO<QueryScheduleHistoryRes>>> getScheduleHistory(@RequestBody QueryScheduleHistoryReq req) {
        QueryRespVO<QueryScheduleHistoryRes> res = scheduleService.queryScheduleHistory(req);
        return ResponseHandler.generateResponse(res);
    }

    @RequestMapping(value = "", method = RequestMethod.POST)
    @ApiOperation(value = "更新注册定时任务", notes = "更新注册定时任务")
    public ResponseEntity<Response<CommonResVO>> updateSchedule(@RequestBody UpdateScheduleReq req) {
        scheduleService.update(req);
        return ResponseHandler.commonResponse();
    }

    @RequestMapping(value = "", method = RequestMethod.DELETE)
    @ApiOperation(value = "删除注册定时任务", notes = "删除注册定时任务")
    public ResponseEntity<Response<CommonResVO>> deleteSchedule(@RequestBody DeleteScheduleReq req) {
        scheduleService.delete(req);
        return ResponseHandler.commonResponse();
    }
}
